package cn.cvs.controller;

import cn.cvs.pojo.Forum;
import cn.cvs.pojo.ForumComment;
import cn.cvs.pojo.SysUser;
import cn.cvs.pojo.User;
import cn.cvs.service.forumcomment.ForumCommentService;
import cn.cvs.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping("/sys/forumComment")
public class ForumCommentController extends BaseController {
    @Autowired
    private ForumCommentService forumCommentService;

    @RequestMapping(value="/add")
    @ResponseBody
    public String add(HttpSession session, ForumComment forumComment){
        User sysUser = (User) session.getAttribute(Constants.USER_SESSION);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        forumComment.setUserId(sysUser.getId());
        forumComment.setCommentTime( format.format(new Date()));
        int count =forumCommentService.addForum(forumComment);
        if(count>0){
            return "true";
        }else{
            return  "false";
        }
    }
}
